package org.example.parse;

import org.example.builder.BaseBuilder;
import org.example.config.Configuration;
import org.example.mapping.ParameterMapping;

import java.util.ArrayList;
import java.util.List;

public class ParameterMappingTokenHandler extends BaseBuilder implements TokenHandler {

    private final Class<?> parameterType;
    private List<ParameterMapping> parameterMappings = new ArrayList<>();

    public ParameterMappingTokenHandler(Configuration configuration, Class<?> parameterType) {
        super(configuration);
        this.parameterType = parameterType;
    }

    public String handleToken(String content) {
        parameterMappings.add(buildParameterMapping(content));
        return "?";
    }

    private ParameterMapping buildParameterMapping(String content) {
        //解析参数属性，找到对应的TypeHandler
        return new ParameterMapping(configuration, content, this.parameterType);
    }

    public List<ParameterMapping> getParameterMappings() {
        return this.parameterMappings;
    }
}